package com.xzh.wms.webselect;

import cn.hutool.core.date.StopWatch;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

//@WebFilter("/api/*")
@Slf4j
public class MyFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("过滤前---");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String url = request.getRequestURI().toString();
        String method = request.getMethod();
        StopWatch stopWatch=new StopWatch();
        stopWatch.start();
        filterChain.doFilter(servletRequest,servletResponse);
        stopWatch.stop();
        log.info("{},{}过滤时间 :{}",url,method,stopWatch.getTotalTimeSeconds());
    }

    @Override
    public void destroy() {
        log.info("销毁后---");
    }
}
